home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / INFOTEXT / ZBOOK.LZH / CH1-3.TXT next >
Text File  |  1988-03-24  |  22KB  |  482 lines

  1. .T:ch.fmt
  2. .K:I.  DIGITAL ARITHMETIC
  3.         I.  DIGITAL ARITHMETIC 
  4.  
  5.  
  6. .I:binary
  7.            Most modern computers are digital computers, based on the binary 
  8.         or base two number system.  In a decimal or base ten number, the 
  9.         least significant or rightmost digit represents the number of ones, 
  10.         the next tens, then hundreds, and so forth.  If we call the least 
  11.         significant digit the 0th then the Nth digit represents the number 
  12.         of 10Ns.  In binary, the Nth digit represents the number of 2Ns.  
  13.         Thus 101 decimal means 1*102 + 0*10 + 1 while 101 binary is 1*22 + 
  14.         0*2 + 1, or decimal five.  When we refer to numbers in different 
  15.         bases we will identify the base by writing it as a subscript after 
  16.         the number.  For example, 1110 is decimal eleven while 112 is the 
  17.         binary equivalent of decimal three. 
  18.         
  19.               decimal: 10110 = 1 * 102 + 0 * 101 + 1 * 100
  20.               binary:  1012  = 1 *  22 + 0 *  21 + 1 *  20
  21.                                  = 4 + 0 + 1 = 510
  22.  
  23. .I:bit
  24. .I:byte
  25.            Binary numbers use only the digits 0 and 1, represented in 
  26.         computers by transistors in either the on (=1) or off (=0) state.  
  27.         A binary digit is called a bit.  A byte is an eight-digit binary 
  28.         number.
  29.         
  30.               bit: 0                     byte: 11010011 (eight bits)
  31.  
  32.            A byte may be transmitted from one group of eight transistors to 
  33.         another over eight wires or lines, through each of which current 
  34.         will flow only if the transistor to which that line is attached is 
  35.         on.  If we were to base a computer on the decimal number system, 
  36.         each transistor would have to be able to represent ten different 
  37.         states corresponding to the digits 0 through 9.  This is done in 
  38.         mechanical adding machines by using gears with ten teeth but there 
  39.         is no easy way to do this electronically. 
  40.  
  41. .I:hexadecimal
  42.            Binary numbers quickly get too long to write conveniently.  It 
  43.         is much easier to write 123410 than its binary equivalent 
  44.         100110100102.  For this reason binary quantities are often 
  45.         represented in hexadecimal (base sixteen) to make them less 
  46.         unwieldy.  This is done by grouping bits by fours starting from the 
  47.         right and converting each group to the corresponding hexadecimal 
  48.         digit as shown in Table 1-1.  Since the hexadecimal number system 
  49.         reqires sixteen symbols for digits, the letters A through F are 
  50.         used to represent the decimal quantities ten through fifteen.  Thus 
  51.         
  52.               100110100102 = 100 1101 0010 = 4D216
  53.  
  54. .I:octal
  55.            Octal or base eight is also used as a shorthand for binary, but 
  56.         not as often as hexadecimal.  A byte breaks neatly into two 
  57.         hexadecimal digits but makes two and a half octal digits.  To 
  58.         convert from binary to octal, group bits by threes instead of fours 
  59.         and convert to digits in the group 0 through 7 (see Table 1-1). 
  60.  
  61. .I:base interconversion
  62.            Converting back to binary from hexadecimal or octal is the same 
  63.         process in reverse.   To convert binary to decimal, multiply each 
  64.         digit by the power of two it represents and add.  Example: 
  65.  
  66. .-
  67.            11012 = 1*23 + 1*22 + 0*2 + 1 = = 8 + 4 + 1 = 1310
  68. .+ 
  69.  
  70.            You could convert octal or hexadecimal numbers to decimal by 
  71.         multiplying each digit by the appropriate power of eight or sixteen 
  72.         (see Table 1) and adding, but you may find it easier to convert to 
  73.         binary and from there to decimal.  Converting decimal to binary is 
  74.         most easily done by repeated integer division by two.  Arranging 
  75.         the remainders in the reverse of the order in which they were 
  76.         obtained gives the binary result: 
  77.  
  78. .-
  79.            13/2 = 6 r 1 
  80.             6/2 = 3 r 0 
  81.             3/2 = 1 r 1 
  82.             1/2 = 0 r 1 --> 1101 = 1x8 + 1x4 + 0x2 + 1x1 = 13
  83. .+ 
  84.  
  85.            Binary numbers are added in the same way as their decimal 
  86.         counterparts.  Starting from the right, each pair of digits and any 
  87.         carry in from the next lower place are added together to produce a 
  88.         single digit sum and carry out: 
  89.  
  90. .-
  91.            step:         1     2 
  92.           carry:        0    10 
  93.             1st:  11    11    11 
  94.             2nd: +10   +10   +10
  95.             sum:         1   101 
  96.                          ^   ^^
  97. .+ 
  98.  
  99. .I:ones complement
  100. .I:twos complement
  101. .I:complement
  102. .I:subtraction
  103.            Binary subtraction could be done like decimal subtraction, but 
  104.         this is not how the microprocessor does it.  By first making the 
  105.         number to be subtracted a negative number and then adding it, the 
  106.         microprocessor does away with the need for separate subtraction 
  107.         circuitry.  Fortunately it is quite easy to negate a binary number.  
  108.         Just change all the zeros to ones and vice-versa (forming the ones 
  109.         complement), then add one (forming the twos complement). 
  110.         
  111.            Forming the ones complement of some eight digit binary number X 
  112.         is the same as subtracting it from 111111112 (try it).  Forming the 
  113.         twos complement by adding one to the ones complement amounts to 
  114.         subtracting it from 1000000002.  When we perform subtraction of a 
  115.         binary number by adding its twos complement, the 1000000002 
  116.         reappears as a carry out of the highest place (which we discard):  
  117.         
  118. .-
  119.            Y + ~X = Y + 111111112 - X + 1 
  120.                   = Y - X + 1000000002
  121. .+ 
  122.  
  123.         In other words, to subtract X from Y, change all of the ones in X 
  124.         to zeroes and the zeroes to ones, add one, add the result to Y, and 
  125.         ignore the carry out of the highest place.  Example: 
  126.  
  127. .-
  128.            5      0101      0101         $ëëLÉèd∩└Σ    H$═ô╚ê≤ê≥    'æµ&Db╤'$$aéd≤≡Qÿææ°díD≤≤≤HττΓ'ττττττττττττττττττττττττττττπ#ππ#'α  gπππ#'τα'τΓ88x `88x8gττττττττττ╔g└└'╞└─@τ└@╟┴g╟└τ└D┴D'└@DB'└τ┴╟D'╟'└D'°8gτττττττ╟Dτ╟└τ├└┴D'└@DB'╟'└D@'┴g└┴─'└─@└τ╞Aαgτ└┴┴'┴'°8gτττττττ╞└─τ└┴─'≡g╞A≡ gτ┬F'└D'╞Aτ┴'└D─τ└└'┬D┬D@τ└┴─'°8gτττττττ┬`τ└D'└─'╞Aτ┴'╟G╟@─'─@g└┴─'└A└─ gτ└┴τ─└τ╞A┬'°8gτττττττ└'╞g┬D┬D@τα#"a±##±'└└'α#"`1##±'┴g└└'╞└─@τ└@╟┴gor 
  129.         unsigned numbers from 0 to 25510.  Either way amounts to 25610 
  130.         different numbers.  Notice that the computer doesn't need to know 
  131.         whether the numbers we are adding are twos complement signed 
  132.         numbers or unsigned numbers: 
  133.  
  134. .-
  135.            101  either 5 or -3 
  136.           +010  equals 2 (signed or unsigned)
  137.            111  either 7 or -1
  138. .+ 
  139.  
  140. .I:overflow
  141.            When the result of an arithmetic operation is too big to be 
  142.         contained in the number of bits available, overflow has occurred.  
  143.         For unsigned arithmetic this happens whenever there is a carry out 
  144.         of the highest bit.  For twos complement arithmetic, this happens 
  145.         when the carries out of the two highest bits are not equal.  
  146.         Example:
  147.         
  148. .-
  149.            carry: 10000  (The carry out of the highest bit is lost) 
  150.              1st:  1001  (9 or -7) 
  151.              2nd: +1010  (10 or -6) 
  152.              sum:  0011  (3.  Should be 19 or -13)
  153. .+
  154.  
  155.            Sometimes you can get away with mixing signed and unsigned 
  156.         numbers, but the usual overflow tests will not work.  for example: 
  157.  
  158. .-
  159.            1010  10 unsigned 
  160.           +1110  -2 signed 
  161.            1000   8 unsigned
  162. .+ 
  163.  
  164.            Binary multiplication and division work just like their decimal 
  165.         counterparts, but only on unsigned numbers.  To perform these 
  166.         operations on signed (twos complement) numbers, use their absolute 
  167.         values and work out the sign of the result later. 
  168.  
  169. 
  170. .-
  171.            110            101 
  172.           x101     110 /11110 
  173.            110          110 
  174.           000             110 
  175.          110              110 
  176.          11110
  177. .+ 
  178.  
  179.  
  180.  
  181.  
  182.  
  183. .-
  184.         Problems 
  185.  
  186.         1. Convert each number below to the other two bases: 
  187.  
  188.            binary  dec  hex 
  189.              1011 
  190.            110010 
  191.            101101 
  192.                     23 
  193.                     47 
  194.                    113 
  195.                          2C 
  196.                          D3
  197. .+ 
  198.  
  199.         2. Convert the decimal numbers in each exercise below to binary, 
  200.         work the problem with the binary numbers, then convert the answer 
  201.         back to decimal to check your answer.  Use twos complement 
  202.         arithmetic for negative numbers. 
  203.  
  204. .-
  205.            a) 5+7  b) 12+16  c) 17+23  d) 53+27 
  206.            e) 7-5  f) 19-3   g) 25-10  h) 48-31 
  207.            i) 9*6  j) 20*13  k) 35/5   l) 144/6 
  208.  .+
  209. .K:Logic
  210.         II. LOGIC 
  211.  
  212.  
  213. .I:gates
  214. .I:logic
  215.            At the heart of all digital computers lie circuits called logic 
  216.         gates, each made up of only a few transistors.  These are combined 
  217.         in different ways to produce most of the electronics in a computer.  
  218.         Logic gates get their names from their similarity to the operators 
  219.         of mathematical logic.  Each has one output which is turned on only 
  220.         for certain combinations of its inputs, each of which may be either 
  221.         on or off.  The actions of the three basic logic gates NOT, AND, 
  222.         and OR reflect the common meanings of these words. 
  223.            
  224. .I:inverter
  225. .I:NOT
  226. .I:AND
  227.            The inverter or NOT gate is the simplest logic gate.  If its 
  228.         input is on, the output is off, and vice versa.  If we let 'on' 
  229.         stand for the logical value 'true' and 'off' stand for 'false' then 
  230.         the connection with mathematical logic becomes more apparent:  the 
  231.         output NOT A is true if the input A is false and false if it is 
  232.         true.  Similarly, the output of the AND gate is on only if all 
  233.         inputs are on.  Thus, for a two-input AND gate, the output A AND B 
  234.         is on only if both inputs A and B are on. 
  235.  
  236. .I:OR
  237. .I:XOR
  238.            There are two kinds of OR gates derived from the inclusive and 
  239.         exclusive OR operators.  The inclusive OR statement A OR B is true 
  240.         if either A or B or both are true.  The exclusive OR statement A 
  241.         XOR B is true if either A or B but not both are true.  Thus, the 
  242.         output of the OR gate is on if any input is but that of the XOR gate 
  243.         is on only if the two inputs are different. 
  244.  
  245. .I:NAND
  246. .I:NOR
  247.            The NOR and NAND gates produce outputs which are the inverse of 
  248.         those produced by the OR and AND gates.  They are equivalent to NOT 
  249.         (A OR B) and NOT (A AND B) respectively, and are what would be 
  250.         obtained if the outputs of the OR or AND gates were passed through 
  251.         an inverter.  Thus, A NOR B is true only when both A and B are 
  252.         false and A NAND B is false only when both are true.  
  253.  
  254. .I:truth table
  255.            It is possible to completely describe the behavior of a logic 
  256.         gate by listing all possible combinations of inputs and the 
  257.         resulting outputs in a tabular form called a truth table.  Here is 
  258.         the truth table for the logic operators described above, shown with 
  259.         the symbols most commonly used to represent these operators in 
  260.         logical expressons.  Study it. 
  261.         
  262.                     NOT  AND  NAND  OR  NOR  XOR
  263.                                                  
  264.                A B   A   A.B  A.B  A+B  A+B  A+OB
  265.                                             
  266.                F F   T    F    T    F    T    F                
  267.                F T   T    F    T    T    F    T
  268.                T F   F    F    T    T    F    T
  269.                T T   F    T    F    T    F    F
  270.          
  271. 
  272. .I:adder, binary
  273.            Logic gates may be combined to perform more complex functions, 
  274.         for example, binary addition.  To add a pair of bits in a binary 
  275.         number, we must calculate a sum (adding in any carry from the next 
  276.         lower bit pair) and a carry out to the next higher bit pair.  Let A 
  277.         and B be the bits to be added, S the sum, Ci the carry in, and Co 
  278.         the carry out.  If we let FALSE stand for zero and TRUE for one, 
  279.         then we can simulate the behavior of the binary functions S and Co 
  280.         as follows: 
  281.  
  282. .-
  283.            S = (A XOR B) XOR Ci and
  284.            Co = (A AND B) OR ((A XOR B) AND Ci)
  285. .+
  286.            To prove this, let's work out the truth tables for these 
  287.         expressons.  First set out all the combinations of A, B, and Ci, 
  288.         then calculate intermediate results, and finally combine these to 
  289.         get S and Co: 
  290.  
  291. .-
  292.                      #1                       #2        #3
  293.            A B Ci  A XOR B  #1 XOR Ci (=S)  A AND B  #1 AND Ci  #2 OR #3 (=Co)
  294.            0 0 0      0         0              0         0          0
  295.            0 0 1      0         1              0         0          0
  296.            0 1 0      1         1              0         0          0
  297.            0 1 1      1         0              0         1          1
  298.            1 0 0      1         1              0         0          0
  299.            1 0 1      1         0              0         1          1
  300.            1 1 0      0         0              1         0          1
  301.            1 1 1      0         1              1         0          1
  302. .+
  303.  
  304.  
  305.         A circuit to perform binary addition according to the above 
  306.         equations is shown in Fig. 2-1.  A circuit to add two bytes can be 
  307.         constructed by connecting eight of these end to end. 
  308. 
  309. .-
  310.         Problems
  311.  
  312.         1. DeMorgan's laws state that
  313.  
  314.            A AND B = (NOT A) NOR (NOT B) and
  315.            A OR B = (NOT A) NAND (NOT B)
  316.  
  317. .+
  318.         Prove these by working out the truth tables for the right and left 
  319.         half of each equation to show they are identical. 
  320.  
  321.         2. A circuit whose output will be on if the two inputs are equal 
  322.         (both on or both off), can be derived from the compound logical 
  323.         expression 
  324.  
  325. .-
  326.            ( A AND B ) OR ( A NOR B ).
  327. .+
  328.  
  329.         Can you come up with a shorter solution? 
  330.  
  331.         3. Draw schematics for the circuits which correspond to these 
  332.         expressions: 
  333.  
  334. .-
  335.            a) A AND NOT B
  336.            b) A OR ( A AND B )
  337.            c) ( A NOR B ) XOR C
  338.            d) A AND B AND
  339. .+
  340. 
  341. .K:III. Microcomputer system overview
  342.                       III. MICROCOMPUTER SYSTEM OVERVIEW 
  343.    
  344.  
  345.  
  346. .I:central processing unit
  347. .I:memory
  348. .I:I/O
  349. .I:microprocessor
  350. .I:integrated circuit
  351. .I:microcomputer
  352.            What is a microprocessor?  All computers, micro or otherwise, 
  353.         have three main components: a central processing unit which does 
  354.         the computing, memory to store programs and data, and I/O or input-
  355.         output circuitry to communicate with the outside world.  A 
  356.         microprocessor is a central processing unit built into a single 
  357.         integrated circuit.  An integrated circuit is a single chip of 
  358.         semiconductor material, the stuff of transistors, but containing up 
  359.         to millions of transistors.  Before the advent of integrated 
  360.         circuits (also called ICs or chips), the central processor 
  361.         typically took up many circuit boards.  A computer which uses a 
  362.         microprocessor is a microcomputer. 
  363.  
  364. .I:microcomputer, single chip
  365. .I:microcontroller
  366.            Integrated circuit technology has progressed to the point that 
  367.         it is now possible to get a central processor, memory, and I/O 
  368.         circuitry all on one chip.  These single-chip microcomputers or 
  369.         microcontrollers do not have enough memory to make them useable as 
  370.         general purpose computers but they are very cost-effective in 
  371.         control applications and are widely used in cars, appliances, and 
  372.         industrial automation.  They are also used extensively in computers 
  373.         as keyboard, display, disk, and other I/O controllers to relieve 
  374.         the main processor of time-consuming I/O tasks. 
  375.  
  376. .I:hardware
  377. .I:program
  378. .I:software
  379. .I:instructions
  380. .I:language, high level
  381. .I:language, machine
  382.            The interaction of the microprocessor, memory, and I/O 
  383.         circuitry, collectively called hardware, is controlled by a program 
  384.         (software) which resides in memory.  A program is composed of 
  385.         instructions, each of which directs the microprocessor to perform a 
  386.         specific task.  The process of running a program begins with the 
  387.         transfer of an instruction from memory to the microprocessor.  
  388.         Instructions in a high level language such as BASIC consist of a 
  389.         collection of English words, numbers, and symbols.  In contrast, 
  390.         instructions in machine language, the native language of the 
  391.         microprocessor, consist entirely of binary numbers.  Each 
  392.         microprocessor has its own machine language into which programs 
  393.         written in higher level languages must be translated before they 
  394.         will run. 
  395.  
  396. .I:address
  397.            The size of the numbers used to represent machine language 
  398.         instructions depends on the microprocessor.  All eight-bit 
  399.         microprocessors transfer a byte of data at a time between the 
  400.         microprocessor and memory.  A machine language instruction will 
  401.         consist of one or more bytes stored in consecutive locations in 
  402.         memory.  Each memory location has a unique address which must be 
  403.         supplied to memory by the microprocessor to specify the location of 
  404.         the byte to be transferred.  Most eight-bit microprocessors use 
  405.         sixteen-bit addresses. 
  406.  
  407. .I:op code
  408.            The first byte of an instruction is usually the op code, a 
  409.         number which specifies the operation the microprocessor is to 
  410.         perform.  Some instructions consist only of an op code.  In others,  
  411.         one or more bytes of additional information follow.  These may be a 
  412.         number to be loaded into the microprocessor, an address, additional 
  413.         information specifying the type of operation to be performed, or 
  414.         some combination of these.  There is no difference between the way 
  415.         data and op codes are represented in memory.  If the microprocessor 
  416.         is expecting an op code, it will treat the byte it receives from 
  417.         memory as an op code.  If it is expecting data, it will treat it as 
  418.         data. 
  419.  
  420. .I:bus
  421.            Data and addresses are moved between the microprocessor and 
  422.         memory or I/O chips on groups of lines called buses.  The data bus 
  423.         in an eight-bit microcomputer system consists of eight lines (wires 
  424.         or printed circuit traces), each of can be either on or off.  In 
  425.         most microprocessors, a potential of 2 to 5 volts is on and 0 to .8 
  426.         volts is off.  The terms high and low are often used instead of on 
  427.         and off.
  428.  
  429.            Each data line and the pin or IC terminal to which it is 
  430.         connected are represented by the letter D followed by a number 
  431.         representing the magnitude of the bit it represents.  D0 represents 
  432.         the least significant bit (the number of 20s or ones) and D7 the 
  433.         most significant (the number of 27s or 128s).  If the binary number 
  434.         10010010 is being transferred over the data bus then D7, D4, and D1 
  435.         will be high and the others low.  The address bus consists of 
  436.         sixteen lines which transfer addresses from the microprocessor to 
  437.         memory or I/O. 
  438.  
  439. .I:control signal
  440. .I:chip select signal
  441.            The data bus allows two-way communication between the 
  442.         microprocessor and other system components.  The direction of the 
  443.         data transfer on the data bus is indicated to memory or I/O by a 
  444.         control signal output by the microprocessor.  This might be high 
  445.         for a read (from memory or I/O) operation and low for a write (to 
  446.         memory or I/O).  Other control signals called chip select signals 
  447.         are necessary to direct the flow of data and addresses to the right 
  448.         chip.  Usually these are active low, meaning that the memory or I/O 
  449.         chip to which the signal is connected will be selected if the line 
  450.         is low. 
  451.  
  452. .I:bus, tri-state
  453.            When its chip select line is high, a memory or I/O chip is 
  454.         electronically disconnected from the address and data buses.  Lines 
  455.         which can be electronically disconnected in this way are called 
  456.         tri-state because they can be on, off, or disconnected (high 
  457.         impedance).  If all of the memory and I/O chips in a microcomputer 
  458.         system have tri-state buses, then bringing only one chip select 
  459.         line low at a time will result in only one memory or I/O chip being 
  460.         connected to the microprocessor at a time.  This reduces output 
  461.         current requirements and prevents contention between two chips for 
  462.         the data bus. 
  463. 
  464.         Problems 
  465.  
  466.         1. What is the difference between a microprocessor, a 
  467.         microcomputer, and a microcontroller? 
  468.  
  469.         2. What are the three main components of a computer?  What does 
  470.         each do? 
  471.  
  472.         3. How does the microprocessor indicate which peripheral chip it 
  473.         wants to communicate with?  How does it indicate whether it intends 
  474.         to send or receive data? 
  475.  
  476.         4. What do the data and address buses do?  What are they connected 
  477.         to? 
  478.  
  479.         5. What are the different possible components of a machine language 
  480.         instruction? 
  481.  
  482.